package org.fanpeng.demo.design;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Collection;

/**
 * className: JDBCUtil
 * Description:
 * date: 2021/9/10 14:58
 *
 * @author fanpeng
 * @version 1.0
 */
public class JDBCUtil {

    private static Logger logger = LoggerFactory.getLogger(JDBCUtil.class);

    public static final String URL = "jdbc:mysql://192.168.200.10:3306/xinli_test_eap?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false";
    public static final String USER = "root";
    public static final String PASSWORD = "root";

    public static void main(String[] args) throws Exception{
        // 1.加载驱动程序
        Class.forName("com.mysql.jdbc.Driver");
        // 2。获取数据库连接
        Connection connection = DriverManager.getConnection(URL, USER, PASSWORD);
        // 3.操作数据库、实现增删改查方法
        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("SELECT * FROM sys_unit ");
        // 如果有数据，rs.next()返回true
        while (resultSet.next()) {
            logger.info("测试结果 公司名称：{} 编码：{}", resultSet.getString("name"),resultSet.getString("code"));
        }

    }


}
